package com.probox.modules.controller.order;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.order.OrderPayInfo;
import com.probox.common.entity.service.order.IOrderPayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 付款流水Controller
 *
 * @author hds
 * @date 2021-06-07
 */
@RestController
@RequestMapping("/order/payInfo")
public class OrderPayInfoController extends BaseController
{
    @Autowired
    private IOrderPayInfoService orderPayInfoService;

/**
 * 查询付款流水列表
 */
@PreAuthorize(hasPermi = "order:payInfo:list")
@GetMapping("/list")
        public TableDataInfo list(OrderPayInfo orderPayInfo)
    {
        startPage();
        List<OrderPayInfo> list = orderPayInfoService.queryList(orderPayInfo);
        return getDataTable(list);
    }

    /**
     * 导出付款流水列表
     */
    @PreAuthorize(hasPermi = "order:payInfo:export")
    @Log(title = "付款流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderPayInfo orderPayInfo) throws IOException
    {
        List<OrderPayInfo> list = orderPayInfoService.queryList(orderPayInfo);
        ExcelUtil<OrderPayInfo> util = new ExcelUtil<OrderPayInfo>(OrderPayInfo.class);
        util.exportExcel(response, list, "付款流水数据");
    }

    /**
     * 获取付款流水详细信息
     */
    @PreAuthorize(hasPermi = "order:payInfo:query")
    @GetMapping(value = "/{payUid}")
    public AjaxResult getInfo(@PathVariable("payUid") Long payUid)
    {
        return AjaxResult.success(orderPayInfoService.selectOrderPayInfoById(payUid));
    }

    /**
     * 新增付款流水
     */
    @PreAuthorize(hasPermi = "order:payInfo:add")
    @Log(title = "付款流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderPayInfo orderPayInfo)
    {
        return toAjax(orderPayInfoService.insertOrderPayInfo(orderPayInfo));
    }

    /**
     * 修改付款流水
     */
    @PreAuthorize(hasPermi = "order:payInfo:edit")
    @Log(title = "付款流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPayInfo orderPayInfo)
    {
        return toAjax(orderPayInfoService.updateOrderPayInfo(orderPayInfo));
    }

    /**
     * 删除付款流水
     */
    @PreAuthorize(hasPermi = "order:payInfo:remove")
    @Log(title = "付款流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{payUids}")
    public AjaxResult remove(@PathVariable Long[] payUids)
    {
        return toAjax(orderPayInfoService.deleteOrderPayInfoByIds(payUids));
    }
}
